﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;

namespace Dal
{
   public class Userdal
    {
        public static Model.User Delu(string Account, string Password)
        {
            string sql = "select * from [user] where Account=@name and Password=@Password";
            SqlParameter[] paras = new SqlParameter[]
            {
                    new SqlParameter("@name",Account),
                    new SqlParameter("@Password",Password)
            };
            SqlDataReader reader = DBhelper.ExecuteReader(sql, System.Data.CommandType.Text, paras);
            List<User> list = new List<User>();
            while (reader.Read())
            {
                User user = new User
                {
                    UserID = Convert.ToInt32(reader["UserID"]),
                    UserName = reader["UserName"].ToString(),
                    Sex = Convert.ToInt32(reader["Sex"]),
                    Account = reader["Account"].ToString(),
                    Password = reader["Password"].ToString(),
                    Phone = reader["Phone"].ToString(),
                    Email = reader["Email"].ToString(),
                    FK_RoleID = Convert.ToInt32(reader["FK_RoleID"]),
                    CheckInTime = Convert.ToDateTime(reader["CheckInTime"]),
                    IsDelete = Convert.ToInt32(reader["IsDelete"]),
                    AlterTime = Convert.ToDateTime(reader["AlterTime"])


                };
                list.Add(user);
                if (list.Count > 0)
                {
                    return user;
                }
            }
            return null;
        }
    }
}
